added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / jsmethodinfo.cs
blob585c2c12fda5de87b6d3f2da59ccf4ab1bd8e817
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using System;
19 using System.Reflection;
20 using System.Reflection.Emit;
21 using System.Globalization;
22 using System.Diagnostics;
24 public sealed class JSMethodInfo : MethodInfo{
25 internal MethodInfo method;
26 private MethodAttributes methAttributes;
27 private String name = null;
28 private Type declaringType = null;
29 private ParameterInfo[] parameters = null;
30 private Object[] attributes = null;
31 private MethodInvoker methodInvoker = null;
33 internal JSMethodInfo(MethodInfo method){
34 this.method = method;
35 this.methAttributes = method.Attributes;
38 public override MethodAttributes Attributes{
39 get{
40 return this.methAttributes;
44 public override Type DeclaringType{
45 get{
46 Type result = this.declaringType;
47 if (result == null) this.declaringType = result = this.method.DeclaringType;
48 return result;
52 public override MethodInfo GetBaseDefinition(){
53 return this.method.GetBaseDefinition();
56 public sealed override Object[] GetCustomAttributes(bool inherit){
57 Object[] attrs = this.attributes;
58 if (attrs != null) return attrs;
59 return this.attributes = this.method.GetCustomAttributes(true);
62 public sealed override Object[] GetCustomAttributes(Type type, bool inherit){
63 if (type != typeof(JSFunctionAttribute))
64 return null;
65 Object[] attrs = this.attributes;
66 if (attrs != null) return attrs;
67 return this.attributes = CustomAttribute.GetCustomAttributes(this.method, type, true);
70 public override MethodImplAttributes GetMethodImplementationFlags(){
71 return this.method.GetMethodImplementationFlags();
74 public override ParameterInfo[] GetParameters(){
75 ParameterInfo[] parameters = this.parameters;
76 if (parameters != null) return parameters;
77 parameters = this.method.GetParameters();
78 for (int i = 0, n = parameters.Length; i < n; i++)
79 parameters[i] = new JSParameterInfo(parameters[i]);
80 return this.parameters = parameters;
83 #if !DEBUG
84 [DebuggerStepThroughAttribute]
85 [DebuggerHiddenAttribute]
86 #endif
87 public override Object Invoke(Object obj, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture){
88 MethodInfo method = TypeReferences.ToExecutionContext(this.method);
89 if (binder != null){
90 try{
91 return method.Invoke(obj, options, binder, parameters, culture);
92 }catch(TargetInvocationException e){
93 throw e.InnerException;
96 MethodInvoker invoker = this.methodInvoker;
97 if (invoker == null){
98 this.methodInvoker = invoker = MethodInvoker.GetInvokerFor(method);
99 if (invoker == null) //because the method is not safe to call via a thunk
100 try{
101 return method.Invoke(obj, options, binder, parameters, culture);
102 }catch(TargetInvocationException e){
103 throw e.InnerException;
106 return invoker.Invoke(obj, parameters);
109 public sealed override bool IsDefined(Type type, bool inherit){
110 Debug.PreCondition(type == typeof(JSFunctionAttribute));
111 Object[] attrs = this.attributes;
112 if (attrs == null)
113 this.attributes = attrs = CustomAttribute.GetCustomAttributes(this.method, type, true);
114 return attrs.Length > 0;
117 public override MemberTypes MemberType{
118 get{
119 return MemberTypes.Method;
123 public override RuntimeMethodHandle MethodHandle{
124 get{
125 return this.method.MethodHandle;
129 public override String Name{
130 get{
131 String result = this.name;
132 if (result == null) this.name = result = this.method.Name;
133 return result;
137 public override Type ReflectedType{
138 get{
139 return this.method.ReflectedType;
143 public override Type ReturnType{
144 get{
145 return this.method.ReturnType;
149 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
150 get {
151 return this.method.ReturnTypeCustomAttributes;
155 public override String ToString(){
156 return this.method.ToString();